package cn.wetcland.es.controller;

import cn.wetcland.es.domain.EsClass;
import cn.wetcland.es.domain.EsStudent;
import cn.wetcland.es.dto.PageDTO;
import cn.wetcland.es.service.EsClassService;
import cn.wetcland.es.service.EsGroupService;
import cn.wetcland.es.service.EsStudentService;
import cn.wetcland.es.service.EsTaskService;
import cn.wetcland.es.utils.MyAssert;
import cn.wetcland.es.vo.EvaluationNodeVO;
import cn.wetcland.es.vo.GroupStuResItemVO;
import cn.wetcland.es.vo.TaskAndStatusListItemVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class PageController {

    @Resource
    private EsTaskService taskService;

    @Resource
    private EsClassService classService;

    @Resource
    private EsStudentService studentService;

    @Resource
    private EsGroupService groupService;

    @RequestMapping("/")
    public String homePage() {
        return "forward:/index";
    }

    @RequestMapping("/index")
    public ModelAndView indexPage(HttpSession session) {
        MyAssert.verifyAlreadyLogin(session);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("index");
        List<List<TaskAndStatusListItemVO>> allTask = taskService.getAllTask(session);
        modelAndView.addObject("allTask", allTask);
        return modelAndView;
    }

    @RequestMapping("/login")
    public ModelAndView loginPage(HttpSession session) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        return modelAndView;
    }

    @RequestMapping("/evaluation")
    public ModelAndView evaluationPage(Long taskId, HttpSession session) {
        MyAssert.verifyAlreadyLogin(session);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("evaluation");
        List<EvaluationNodeVO> evaluationNodeVOS = taskService.genEvalTableByTaskId(taskId);
        modelAndView.addObject("evaluationNodeVOS", evaluationNodeVOS);
        return modelAndView;
    }

    @RequestMapping("/manageClass")
    public ModelAndView manageClassPage(PageDTO pageDTO, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manage-class");
        Page<EsClass> pageClassList = classService.getPageClassList(pageDTO);
        modelAndView.addObject("pageData", pageClassList);
        return modelAndView;
    }

    @RequestMapping("/manageStudent")
    public ModelAndView manageStudentPage(Long classId, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manage-student");
        List<EsStudent> allStudent = studentService.getAllStudent(classId);
        modelAndView.addObject("studentList", allStudent);
        return modelAndView;
    }

    @RequestMapping("/manageGroup")
    public ModelAndView manageGroupPage(Long classId, HttpSession session) {
        MyAssert.verifyRoleTeacher(session);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("manage-group");
        List<GroupStuResItemVO> groupStuListItemVOS = groupService.getGroupListByClassId(classId);
        List<EsStudent> allStudent = studentService.getAllStudent(classId);
        modelAndView.addObject("groupStuList", groupStuListItemVOS);
        modelAndView.addObject("students", allStudent);
        return modelAndView;
    }

    @RequestMapping("/charts-bar-self")
    public ModelAndView chartsBarSelf() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("charts-bar-self");
        return modelAndView;
    }

    @RequestMapping("/charts-radar-self")
    public ModelAndView chartsRadarSelf() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("charts-radar-self");
        return modelAndView;
    }

    @RequestMapping("/comprehensive-charts")
    public ModelAndView comprehensiveCharts() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("comprehensive-charts");
        return modelAndView;
    }

    @RequestMapping("/pre-result")
    public ModelAndView preResult() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pre-result");
        return modelAndView;
    }

}
